package com.zeng.sboot.amqp.producer.config.amqp;

import com.alibaba.fastjson.JSON;
import com.zeng.sboot.demo.amqp.config.RabbitmqConfig;
import com.zeng.sboot.demo.amqp.domain.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EmailSmsSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sender() {
//        for (int i = 0; i < 5; i++) {
//            Order order = new Order(1l + i, "商品：good-" + (i + 1), "item-" + (i + 1));
//            String str = JSON.toJSONString(order);
//
//            rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.sms.email",str);
//        }
        for(int i = 0; i< 5 ;i++) {
            Order order = new Order(1l + i, "商品：good-" + (i + 1), "item-" + (i + 1));
            System.out.println(order);
            rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.sms.email",order);
        }
    }
}
